home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.02 Feb 90 / Mouse Source / TrackInit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-07-22  |  2.1 KB  |  97 lines  |  [TEXT/KAHL]

  1. /*                                            TrackInit.c                                            */
  2. /*
  3.  * Copyright © 1989 Martin Minow. All rights reserved.
  4.  *
  5.  * void
  6.  * TrackInit()
  7.  *
  8.  * TrackHandle
  9.  * TrackNew(dest, view)
  10.  * Rect                    *dest;
  11.  * Rect                    *view;
  12.  *
  13.  * void
  14.  * TrackDispose(track_handle)
  15.  * TrackHandle    track_handle;
  16.  *
  17.  * Initialize, create, and destroy TrackRecords.
  18.  */
  19. #include    "TrackEdit.h"
  20. #define TR    (*tr)
  21.  
  22. /*
  23.  * Track library private data.
  24.  */
  25. Handle            TrackScrpHandle;                /* Track Scrap            */
  26. LONGINT            TrackScrpLength;                /* Scrap length            */
  27.  
  28. void
  29. TrackInit()
  30. {
  31.         TrackScrpHandle = NewHandle(0);
  32.         TrackScrpLength = 0;
  33. }
  34.  
  35. TrackHandle
  36. TrackNew(line_width, viewRectp)
  37. INTEGER    line_width;
  38. Rect        *viewRectp;
  39. {
  40.         TrackHandle                track_handle;
  41.         TrackPtr                    tr;
  42.         register char            *ptr;
  43.         register int            i;
  44.         FontInfo                    info;
  45.         Handle                        temp;
  46.         
  47.         track_handle =
  48.             (TrackHandle) NewHandle(sizeof (TrackRecord));
  49.         /*
  50.          * Initialize the record by clearing out all fields.
  51.          * Note that we can't call _Track_lock here.
  52.          */
  53.         HLock(track_handle);
  54.         tr = (*track_handle);
  55.         ptr = (char *) tr;
  56.         for (i = 0; i < sizeof (TrackRecord); i++)
  57.             *ptr++ = 0;
  58.         TR.inPort = thePort;
  59.         TR.hText = NewHandle(0L);
  60.         /*
  61.          * Test whether the ScriptManager is installed,
  62.          * Note that the ROMS must not change while the
  63.          * program is running.
  64.          */
  65. #define    Unimplemented    0x9F
  66. #define    ScriptUtil        0xB5
  67.         if ((GetTrapAddress(Unimplemented)
  68.           != GetTrapAddress(ScriptUtil))
  69.          && GetEnvirons(smEnabled)) {
  70.             _Track_set(tr, _Track_has_script_manager);
  71.             _Track_set(tr, _Track_use_script_manager);
  72.             _Track_set(tr, _Track_use_smart_cut_paste);
  73.         }
  74.         TR.lineWidth = line_width;
  75.         TR.viewRect = *viewRectp;
  76.         TR.txFont = thePort->txFont;
  77.         TR.txFace = thePort->txFace;
  78.         TR.txMode = thePort->txMode;
  79.         TR.txSize = thePort->txSize;
  80.         GetFontInfo(&info);
  81.         TR.fontAscent = info.ascent;
  82.         TR.fontDescent = info.descent;
  83.         TR.lineHeight =
  84.             info.ascent + info.descent + info.leading;
  85.         HUnlock(track_handle);
  86.         return (track_handle);
  87. }
  88.  
  89. void
  90. TrackDispose(track_handle)
  91. TrackHandle    track_handle;
  92. {
  93.         DisposHandle((*track_handle)->hText);
  94.         DisposHandle(track_handle);
  95. }
  96.  
  97.